package at.main.android;
/* 
 *  Convert J2ME to Android v.001
 *  Author: Van Tan Tai 
 *  Mail  : itvan@live.com
 *  Date  : 11.11.2010
 * 
 */
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;

public class Implement {
	
	public static Implement instance = null;
	private MIDlet mid = null;
	private CanvasJ2ME can = null;
	public Graphics g = null;
	
	public Display  display;
	
	public Implement(Activity app, View view) {
		display=((WindowManager)app.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		instance = this;
		Static.App = app;
		Static.view = view;
	}

	public void _startApp(MIDlet midlet){
		mid = midlet; 
		this.start();
	}
	public void start() {
		try {
			mid.startApp();
			can = CanvasJ2ME.instance; // just: 1 midlet & 1 Canvas
			can.showNotify();
		} catch (MIDletStateChangeException e) {
			e.printStackTrace();
		}
	}
	public void destroy() {
		try {
			mid.destroyApp(true);
		} catch (MIDletStateChangeException e) {
			e.printStackTrace();
		}
	}
	public void pause() {
		mid.pauseApp();
		can.hideNotify();
	}
	
//	public void keyDown(int keyCode) {
//		can.keyPressed(keyCode);
//	}
//	public void keyUp(int keyCode) {
//		can.keyReleased(keyCode);
//	}
//	public void keyRepeated(int keyCode) { // event
//		can.keyRepeated(keyCode);
//	}
//	public void pointerDragged(int x, int y) {
//		can.pointerDragged(x, y);
//	}
//	public void pointerPressed(int x, int y) {
//		can.pointerPressed(x, y);
//	}
//	public void pointerReleased(int x, int y) {
//		can.pointerReleased(x, y);
//	}
//	public void resize(int width, int height){
//		can.sizeChanged(width, height);
//	}
	
	public void paint(Canvas canvas) {
		if(g == null){
			g = new Graphics(canvas);
		}
		g.resetTranslate();
		can.paint(g);
	}
}
